package main;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.stage.Stage;

import org.apache.log4j.Logger;

import ui.WorkUI;
import utility.AppUtilities;

public class MyUI_FX extends Application {
	private final static Logger logger = Logger.getLogger(MyUI_FX.class);

	@Override
	public void start(Stage stage) throws Exception {
		try {
			WorkUI workUi = new WorkUI(stage);
			Scene scene = workUi.getScene();
			// create scene
			stage.setTitle("Web View");
			stage.setScene(scene);
			// show stage
			stage.show();
		}catch (Exception e) {
			StringBuffer sb = new StringBuffer(e.toString() + "\n");

			for(StackTraceElement st : e.getStackTrace()) {
				sb.append(st.toString() + "\n");
			}

			logger.error(sb.toString(), e.getCause());
			Platform.exit();
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		AppUtilities appUtilities = AppUtilities.createAppUtilities();
		if(appUtilities.isFILEOOExisting()) {
			logger.warn("An instance of this application may be runnign already.\n To run new instance:\n\t-Turn off the already running \n\t-Or delete file OOI.ooi in configuration folder.");
			System.exit(1);
		}

		launch(args);
		System.exit(0);
	}

}
